package com.code.view.listeners;

import java.util.Hashtable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import com.code.view.ViewUtils;
import com.code.view.entity.TableItemControl;


/**
 * 新增按钮事件监听类
 *
 *
 * @author 朱国军
 * @version 2015年3月5日 朱国军
 */
public class AddMouseListener implements MouseListener {
    private Table table;

    private Shell shell;

    private Hashtable<TableItem, TableItemControl> tableControls;

    private String[][] contents = { { "0", "", "" } };


    /**
     * 构造函数
     *
     * @param table 表格
     * @param shell 显示页面
     * @param tableControls 表格控件
     */
    public AddMouseListener(Table table, Shell shell, Hashtable<TableItem, TableItemControl> tableControls) {
        this.table = table;
        this.shell = shell;
        this.tableControls = tableControls;
        contents[0][2] = ViewUtils.readPackagePathValue();
    }


    @Override
    public void mouseUp(MouseEvent arg0) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(contents[0]);
        // 创建一个item的控件
        ViewUtils.createOneItemCells(item, table, tableControls);
        if (shell.getBounds().height > (table.getBounds().y + table.getBounds().height + 108)) {
            table.setSize(table.computeSize(shell.getBounds().width - 60, SWT.DEFAULT, true));
        } else {
            table.setSize(table.computeSize(shell.getBounds().width - 60, shell.getBounds().height - table.getBounds().y - 108, true));
        }
    }


    @Override
    public void mouseDown(MouseEvent arg0) {

    }


    @Override
    public void mouseDoubleClick(MouseEvent arg0) {

    }
}
